package com.liangplus.elasticsearch.controller;

import com.liangplus.elasticsearch.entity.eo.ShrEO;
import com.liangplus.elasticsearch.entity.eo.UserPEO;
import com.liangplus.elasticsearch.service.QueryService;
import org.elasticsearch.search.SearchHits;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created by yumin on 2019/8/2.
 */
@Controller
@RequestMapping("/query")
public class QueryController {

    @Autowired
    private QueryService queryService;

    @GetMapping(value = "match/{keyword}")
    @ResponseBody
    public Page<ShrEO> fullSearch(@PathVariable String keyword) {
        return queryService.fullSearch(keyword,1,10);
    }

    @GetMapping(value = "match2/{keyword}")
    @ResponseBody
    public Page<UserPEO> fullSearch2(@PathVariable String keyword) {
        return queryService.fullSearchForUser(keyword,1,10);
    }


    @GetMapping(value = "term/{keyword}")
    @ResponseBody
    public Page<UserPEO> termSearch(@PathVariable String keyword) {
        return queryService.termSearch(keyword,1,10);
    }

    @GetMapping(value = "term2/{keyword}")
    @ResponseBody
    public Page<UserPEO> termQuery(@PathVariable String keyword) {
        return queryService.termQuery(keyword,1,10);
    }

    @GetMapping(value = "term3/{keyword}")
    @ResponseBody
    public SearchHits multiMatchQuery(@PathVariable String keyword) {
        return queryService.multiMatchQuery(keyword,1,10);
    }

    @GetMapping(value = "term5/{keyword}")
    @ResponseBody
    public SearchHits multiMatchQuery2(@PathVariable String keyword) {
        return queryService.multiMatchQuery2(keyword,1,10);
    }


}
